package com.itheima.map.mapdemo;

import java.util.*;

public class MyMap4 {
    public static void main(String[] args) {
        Map<String, ArrayList<String>> map = new HashMap<>();

        ArrayList<String> xiYouJi = new ArrayList<>();
        Collections.addAll(xiYouJi, "孙悟空", "唐僧", "猪八戒", "沙僧");

        ArrayList<String> shuiHuZhuan = new ArrayList<>();
        Collections.addAll(shuiHuZhuan, "宋江", "武松", "武大郎", "卢俊义");

        ArrayList<String> sanGuo = new ArrayList<>();
        Collections.addAll(sanGuo, "诸葛亮", "吕布", "潘凤", "鲁肃");

        ArrayList<String> hongLouMeng = new ArrayList<>();
        Collections.addAll(hongLouMeng, "林黛玉", "贾宝玉", "刘姥姥", "薛宝钗");

        map.put("西游记", xiYouJi);
        map.put("水浒传", shuiHuZhuan);
        map.put("三国演义", sanGuo);
        map.put("红楼梦", hongLouMeng);

        Set<Map.Entry<String, ArrayList<String>>> entries = map.entrySet();
        for (Map.Entry<String, ArrayList<String>> entry : entries) {
            String key = entry.getKey();
            System.out.println(key + ": ");
            System.out.print("\t");

            ArrayList<String> list = map.get(key);
            for (int i = 0; i < list.size(); i++) {
                String value = list.get(i);
                if (i != list.size() - 1){
                    System.out.print(value+",");
                }else {
                    System.out.println(value);
                }
            }

        }
    }
}
